Part Number Hot Search : 
1N1199 TFS70L14 CS8430 MC32N C3216X5 A680M NTE2538 P10N05
Product Description
Full Text Search
 

To Download AN1278 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  AN1278/0502 1/44 AN1278 application note lin (local interconnect network) solutions by microcontroller division applications introduction many mechanical components in the automotive sector have been replaced or are now being replaced by intelligent mechatronical systems. a lot of wires are needed to connect these components. to reduce the amount of wires and to handle communications between these systems, many car manufacturers have created different bus systems that are incompatible with each other. in order to have a standard sub-bus, car manufacturers in europe have formed a consortium to define a new communications standard for the automotive sector. the new bus, called lin bus, was invented to be used in simple switching applications like car seats, door locks, sun roofs, rain sensors, mirrors and so on. the lin bus is a sub-bus system based on a serial communications protocol. the bus is a single master / multiple slave bus that uses a single wire to transmit data. to reduce costs, components can be driven without crystal or ceramic resonators. time syn- chronization permits the correct transmission and reception of data. the system is based on a uart / sci hardware interface that is common to most microcontrollers. the bus detects defective nodes in the network. data checksum and parity check guarantee safety and error detection. as a long-standing partner to the automotive industry, stmicroelectronics offers a complete range of lin silicon products: slave and master lin microcontrollers covering the protocol handler part and lin transceivers for the physical line interface. for a quick start with lin, stmicroelectronics supports you with lin software enabling you to rapidly set up your first lin communication and focus on your specific application requirements. figure 1. lin network overview master slave slave slave lin bus can bus 1
2/44 table of contents 44 2 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 lin protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 lin products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1 lin microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1.1 lin slave mcus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1.2 lin master mcus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2 lin transceivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2.1 l9637 k-line transceiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2.2 l9638 lin transceiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3 lin software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.1 types and macro definitions: lib.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1.1 debug settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1.2 types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1.3 macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2 protocol handler: lin.p/h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2.1 type definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.2.2 user interface functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.2.3 timeout handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.2.3.1 initializing the timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.3 lin configuration file: lin_config.h . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.4 application interface: lin_ai.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4 examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.1 implementation on the st72254g2 - software emulated sci . . . 25 4.1.1 step by step configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.2 implementation on the st72334n4 - hardware sci . . . . . . . . . . . . . 28 4.2.1 step by step configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.2.1.1 lin_config.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.2.1.2 lin_ai.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.2.1.3 master data request (datarequest_notification) . . . . . . . . . . . . . 30 4.2.1.4 data reception (datareceived_notification) . . . . . . . . . . . . . . . . 30 4.3 stmicroelectronics lin package - example installation . . . . 33 4.3.1 lin package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 4.3.2 quick start with stvd7 and cosmic c compiler . . . . . . . . . . . . . . . . . . . . 33 4.4 performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.4.1 timing considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4.4.2 using the emulated sci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4.4.2.1 reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.4.2.2 transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3/44 table of contents 4.4.3 using the on-chip sci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.4.3.1 reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.4.3.2 transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 5 summary of changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 1
4/44 lin (local interconnect network) solutions 1 lin protocol the aim of this chapter is to give an overview of the lin protocol and concept. for detailed and up-to-date information please refer to the official lin homepage: www.lin-subbus.org where you can register for the lin specification package. the lin specification package consists of three parts: n the lin protocol specification n the lin configuration language description n the lin api the first part describes the lin physical and data link layers. the second part describes the lin configuration language. the lin configuration language enables the user lin network to be described in a file (how many nodes, how many frames, frame description, baudrate etc.). the goal of this specification is to ease communications between the parties involved in the development of a lin network like car manufacturers and their suppliers. the third and last part is about the software implementation of the lin protocol and specifies some points on how the software implementation has to be done. the lin concept uses a single master / multiple slave model. only the master is able to initiate a communication. a lin frame consists of a header and a response part. to initiate a commu- nication with a slave the master sends the header part. if the master wants to send data to the slave it goes on sending the response part. if the master requests data from the slave the slave sends the response part. figure 2. basics of lin communication direct communication between slaves is not possible. but as all nodes always listen to the bus, a master request can be used to handle slave-to-slave communications. master slave 1 slave 2 header response 1 lin frame sent by: master slave 1 slave 2 master to slave 1 slave 2 to master lin bus
5/44 lin (local interconnect network) solutions the lin protocol is object-oriented and not address-oriented. the header contains the identi- fier which identifies the lin frame and the data it contains. different nodes may receive the same frame data. the response part consists mainly of data of selectable length (1 to 8 bytes). the data are se- cured by an 8 bit checksum. the lin protocol is time-trigger oriented. the master periodically sends the same sequence of lin frames. each sequence, the master and the slaves update the data they send and re- ceive. the sequence sent by the master may change depending on application events. example: the slave is a sensor measuring a analog value which is communicated to the master via lin. the slave continuously measures its analog input independently from the lin communication. in response to a master request (periodical) the slave sends the up-to-date/ last measured value of the analog input. figure 3. time-triggered protocol in order to achieve a good level of security, different mechanisms exist like parity bits on the identifier or checksum on data bytes. one important feature of the protocol is to enable the slave mcus to run with low cost oscilla- tors such as an integrated rc oscillator provided that the accuracy is better than +/-15%. for this purpose the header contains a sync field byte consisting of the constant 0x55. this byte enables each slave to measure the master bit time and to synchronize its clock accordingly. in order to obtain very low power consumption, the master is able to send a sleep frame. any node can go into low power mode. to wake up the network, any node can send a so-called wake-up signal. master slave 1 slave 2 1 sequence analog value:25 analog change value analog value:38 25 25 38 38 lin bus
6/44 lin (local interconnect network) solutions figure 4. sleep mode - wake-up sleep mode command wake-up signal normal mode sleep mode network start-up normal mode
7/44 lin (local interconnect network) solutions 2 lin products a typical lin node consists of a microcontroller for handling the lin protocol and a lin trans- ceiver for interfacing the digital part and the physical line (see figure 5 . lin bus topology ). stmicroelectronics offers both kind of products. figure 5. lin bus topology 2.1 lin microcontrollers stmicroelectronics offers a wide range of microcontrollers suitable for master and/or slave nodes. 2.1.1 lin slave mcus table 1. very low cost lin slave mcus - full software solution - flash/rom mcus features st72104g1 st72104g2 st72216g1 st72215g2 st72254g1 st72254g2 program memory - bytes 4k 8k 4k 8k 4k 8k ram (stack) - bytes 256 (128) peripherals watchdog timer, one 16- bit timer, spi watchdog timer, one 16-bit timer, spi, adc watchdog timer, two16-bit timers, spi, adc watchdog timer, two 16- bit timers, spi, i2c, adc operating supply 3.2v to 5.5v cpu frequency up to 8mhz (with oscillator up to 16 mhz) operating tempera- ture -40c to +85c (-40c to +105/125c optional) packages so28 / sdip32 master slave slave slave microcontroller rx tx transceiver lin bus lin bus
8/44 lin (local interconnect network) solutions table 2. low cost lin slave mcus with hardware sci - flash/rom mcus 2.1.2 lin master mcus table 3. eprom/otp/rom mcus table 4. flash, rom mcus (st7 core) features st72124j2 st72314j2 st72314j4 st72314n2 st72314n4 st72334j2 st72334j4 st72334n2 st72334n4 program memory - bytes 8k 8k 16k 8k 16k 8k 16k 8k 16k ram (stack) - bytes 384 (256) 384 (256) 512 (256) 384 (256) 512 (256) 384 (256) 512 (256) 384 (256) 512 (256) peripherals watchdog timer, two 16-bit timers, spi, sci -adc operating supply 3.0v to 5.5v cpu frequency up to 8mhz (with up to 16mhz oscillator) operating tem- perature -40c to +85c (-40c to +105/125c optional) packages tqfp44/sdip42 tqf64/sdip56 tqf44/sdip42 tqf64/sdip56 features st72511r9 st72511r7 st72511r6 program memory - bytes 60k 48k 32k ram (stack) - bytes 2048 (256) 1536 (256) 1024 (256) peripherals watchdog timer, two 16-bit timers, 8-bit pwm art, spi, adc operating supply 3.0v to 5.5v cpu frequency up to 8mhz (with oscillator up to 16 mhz) operating tempera- ture -40c to +85c (-40c to +105/125c optional) packages tqfp64 features st72521r/m9 st72521r/m7 st72521r/m6 st72521r5 st72521r4 program memory - bytes 60k 48k 32k 24k 16k ram (stack) - bytes 2048 (256) 1536 (256) 1024 (256) 768 (256) 512 (256) peripherals watchdog timer, 16-bit timers, spi, sci, 10-bit adc, can 8-bit pwm art, i2c 8-bit pwm art operating supply 2.7v to 5.5v cpu frequency 16 to 50khz (with 32 to 100khz oscillator), 500 to 8 mhz (with 1 to 16 mhz oscil- lator), 2 to 8 mhz (with 2 to 4 mhz oscillator and pll) operating tempera- ture 0c to 70c/-40c to +85c/-40c to +105c/-40c to +125c/ packages tqfp80(m), tqfp64 (r)
9/44 lin (local interconnect network) solutions table 5. flash, rom mcus (st9 core) note: the master mcus listed above have all an on-chip can peripheral. this corresponds to the initial lin concept: the lin network as sub-network of can. however any other mcus (listed above as slave for example) can be used to implement a master node. 2.2 lin transceivers to ensure the physical behaviour of the lin bus stmicroelectronics also offers k-line drivers and a dedicated lin bus transceiver. 2.2.1 l9637 k-line transceiver the l9637 k-line transceiver is a monolithic integrated circuit containing standard iso 9141 compatible interface functions. its features are listed below. n operating power supply voltage range 4.5v v s 36v (40v for transients) n reverse supply battery protected down to v s 3 -24v n stand-by mode with very low current consumption is sb 1 m a @vcc 0.5v n low quiescent current in off condition is off = 120 m a n ttl compatible tx input n bidirectional k-i/o pin with supply voltage dependent input threshold n overtemperature shut down function selective to k-i/o pin n wide input and output voltage range -24v v k v s n k output current limitation, typical i k = 60ma n defined off output status in under voltage condition and v s or gnd interruption n controlled output slope for low emi n high input impedance for open v s or gnd connection n defined output on status of lo or rx for open li or k inputs n defined k output off for tx input open features st92f150jd st92f150jc st92f124j st92f124 flash - bytes 128k 60/128k 60/128k 60/128k ram - bytes 6k 2/4k 2/4k 2/4k eeprom - bytes1k 1k1k1k timers 2mft, 2 eft, stim, wd 2mft, 0/2 eft, stim, wd serial interface 2 sci, spi, i2c 1/2 sci, spi, i2c adc 16 x 10 bits 8/16 x 10 bits network interface 2 can, j1850 can, j1850 j1850 - temp. range -40c to 125c or -40c to 85c package p/tqfp100 p/tqfp100 and tqfp64
10/44 lin (local interconnect network) solutions n integrated pull up resistors for tx, rx and lo n emi robustness optimized 2.2.2 l9638 lin transceiver the l9638 lin transceiver is a monolithic integrated circuit fulfilling the lin specification. its features are listed below. n wake up capability by: - lin bus - external signal (edge triggered) n system wake up functions: - inhibit output - rxd output n quiescent current less than 25a n fail safe functions implemented n pin compatible to l9637 figure 6. l9638 block diagram glitch filter control logic protection internal voltage regulator v s r x d t x d en wup lin inh gnd int.5v glitch filter
11/44 lin (local interconnect network) solutions the following figure ( figure 7 ) shows a typical application of the l9638 lin transceiver to- gether with the st72124j microcontroller and a voltage regulator. figure 7. application of l9638 with st72124j microcontroller the voltage regulator supplies the application and generates the mcu reset signal. the lin transceiver is the physical line interface between the sci (serial communication interface) tdi and rdo pins of the microcontroller and the lin bus line. the microcontroller handles the lin protocol and the application functions. in order to lower power consumption the microcontroller is able to switch off the lin trans- ceiver via the l9638 en input. the transceiver is then able to switch off the voltage regulator by connecting its inh output to the en input of the voltage regulator. in this state any ac- tivity on the lin bus will cause the l9638 to wake the voltage regulator up via the inh pin. another wake-up source is the wup pin of the l9638 that can be used for contact sensing. any edge on this pin will also wake up the regulator. lin node vbatt lin lin rxd txd inh en lin wup vs gnd reset gnd vdd tdi rdo i/o pin vs vout res voltage regulator st72124j mcu transceiver en l9638 gnd vdd
12/44 lin (local interconnect network) solutions 3 lin software table 6. software overview the lin standard includes the specification of the communication protocol but also the use of associated tools. stmicroelectronics supports the development of your lin application by providing ready-to- use lin software. this software only handles the communication protocol part. for a complete software development tool solution you can contact lin specialist third party tools manufac- turers like vct (http://www.vct.se) or vector (http://www.vector-informatik.de). the software supports lin slave nodes. it consists of 4 files: C lin.c/h: protocol handler code C lin_config.c: lin parameter configuration file C lin_ai.c: application interface a fifth additional file is delivered: C lib.h: library file (macros, types definition) the software supports the cosmic c compiler. figure 8. software architecture version 2.0 supported nodes slave supported mcus all st7 mcus lin protocol specification revision rev 1.2 application lin-ai.c lin.c hardware interrupt application specifics lin message lin_config.h
13/44 lin (local interconnect network) solutions the software is interrupt driven. as soon as a message begins on the bus, an interrupt is gen- erated and automatically handles the protocol. this means that the protocol handler is totally autonomous. it runs in the background. when the received frame is decoded by the software this is notified to the application in the lin_ai.c. in this file the user is able to customize the be- haviour of the application upon reception of a frame for example. 3.1 types and macro definitions: lib.h 3.1.1 debug settings see 4.4.1 timing considerations 3.1.2 types the software uses predefined types for 1-byte and 2-byte variables. the name used for the one-byte type is ubyte. the name used the two-byte type is uword. beside these, a third type is used to define two-byte variables that can also be accessed high byte or low byte only. typedef union { unsigned int w_form; struct { unsigned char high, low; } b_form; } twobytes; these types are defined in the lib.h file. 3.1.3 macros three macros for register bit access are defined: C setbit(var,pos): set bit pos of var variable C clrbit(var,pos): clear bit pos of var variable C valbit(var,pos): test bit pos of var variable. return 0 if reset another value otherwise. 3.2 protocol handler: lin.p/h the lin.p file contains the protocol handler. the user has no access to this file. it should simply be linked to the rest of the application. the lin.p file is encrypted and can therefore not be read but must be compiled and linked to the rest of the application. the lin.h contains the definition of new types and the prototypes of the functions defined in lin.c.
14/44 lin (local interconnect network) solutions 3.2.1 type definition t_error typedef enum {no_error,bit_error,id_parity_error,checksum_error, no_id_match,timeout_error,data_received,data_request, wake_up,uart_error,synch_break_error}t_error; defines the different error code values that the software functions are able to return. t_message_direction typedef enum {id_datarequest,id_datasent}t_message_direction; this type is used internally in lin.c and in lin_drv.c. t_id_list typedef struct{ ubyte id; t_message_direction dir; ubyte length;} t_id_list; defines the type of an identifier list. t_one_databyte_output typedef struct{ t_error error_code; ubyte data_byte;} t_one_databyte_output; defines a type of function return value consisting of an error code made up of error type and a data byte. t_header typedef struct { ubyte identifier; ubyte length;} t_header; a lin frame consists of a header and a response. this typedef defines the header part type. t_response typedef struct { ubyte data[8]; ubyte checksum;} t_response; a lin frame consists of a header and a response. this typedef defines the response part type. 3.2.2 user interface functions to integrate this software into your application software you have to link 3 or 4 functions de- fined in lin.c to your project.
15/44 lin (local interconnect network) solutions here are the prototypes of these functions: 3.2.3 timeout handling the lin communication timeout handling is done using one output compare (oc) feature of the 16 bit timer. if the sci communication is emulated using a 16 bit timer (uses one oc and one ic) the user can and should define the same timer for both the sci communication and the timeout handling. in this case the timer is fully used for the lin communication and the lin software takes full control of the selected timer. if the user decides to configure 2 different timers for the sci communication and the timeout handling or if the sci is not emulated by a 16 bit timer; timeouts are handled using only one oc of a separate timer. in order to leave the unused oc/ic features free for the application, the application software is responsible for: function void lin_init(void) parameters none return value none description lin communication initialization has to be called after reset function void lin_sendwakeupsignal(void) parameters none return value none description when the lin network is in sleep mode and the application wants to wake it up, this function has to be called to send a wakeup frame. function void lin_interrupt(void) parameters none return value none description lin interrupt service routine. you should link this function to the corresponding interrupt vector: timer or sci interrupt according to the sci hardware used (see 3.3 lin configuration file: lin_config.h ). function void lintimeout_interrupt(void) parameters none return value none description lin timeout interrupt service routine (exists only in some cases). it only exists if sci is defined or if the timer defined for timeouts is not the one used for the sci emulation you should link this function to the corresponding timer interrupt vector (see 3.2.3 timeout handling and 3.3 lin configuration file: lin_config.h ).
16/44 lin (local interconnect network) solutions 3.2.3.1 initializing the timer the application can initialize the resources that are not used by the lin software as needed but is also responsible for initializing the oc defined for the timeouts handling in this way: oc interrupt the ocie flag in control register 1 must be set. a write access must be made to the high byte of the defined output compare register to disable the corresponding interrupt separately. the lin software will enable it when needed. if the application is not using the other output compare, a write access must be done to the high byte of the corresponding output compare register to disable the feature. timer clock initialization the timer clock/prescaler has to be defined to fulfil the lin software requirements. the reason is that the timeouts to be handled must be smaller than a timer period otherwise the output compare cannot work properly. the lin software takes the faster clock that respects this con- dition. the prescaler to be set can be calculated using the following equations. the smallest value (2,4, or 8) that fulfils the equation is the prescaler value. table 7. equation for prescaler value calculation timer interrupt initialization the lin software will use the define oc feature in such a way that an oc interrupt will be gen- erated if a lin communication timeout occurs. the corresponding timer interrupt has to be de- fined by the application and the lintimeout_interrupt function described above has to be in- serted in it. the function checks if the ocxf flag is set and resets it after completion. 3.3 lin configuration file: lin_conf ig.h the lin_config.h file allows the user to configure the lin communication. the following sym- bols should be set: #define fcpu #define uart_timera #define uart_timerb sci emulation (fcpu/prescaler/baudrate)*163 < 65536 sci emulation & resynchr. 1,15*(fcpu/prescaler/baudrate)*163 < 65536 on-chip sci used (fcpu/prescaler/baudrate)*165 < 65536 #define fcpu description speed in mhz of the mcu internal frequency
17/44 lin (local interconnect network) solutions #define sci #define lin_port_add #define lin_rx_pinnb example: st72-104/215/216/254 mcu family #define uart_timera, uart_timerb or sci description define only one of these options. define uart_timera or uart_timerb if you use a mi- crocontroller without sci and depending on the tim- er you want to use. the serial communication will be emulated by software with a timer. if you use a microcontroller with an on-chip sci, define sci. the hardware sci peripheral will be used. #define lin_port_add description needs to be defined only if uart_timera or uart_timerb is defined. set which pin is the lin rx pin. this symbol should be set to the address of the data register of the i/o port linked to the lin rx pin (pc3>set address of pcdr register). #define lin_rx_pinnb description needs to be defined only if uart_timera or uart_timerb is defined. set which pin is the lin rx pin. this symbol should be set to the number of the pin linked to the lin rx pin (pc3>set 3). sci emulated by timer a sci emulated by timer b lin rx on ic1 lin rx on ic2 lin rx on ic1 lin rx on ic2 lin rx is pin: pb0 (port b pin 0) pb2 (port b pin 2) pc0 (port c pin 0) pc3 (port c pin 3) lin_port_add 0x04 0x04 0x00 0x00 lin_rxc_pinnb 0203
18/44 lin (local interconnect network) solutions #define uart_ic1 #define uart_ic2 #define uart_oc1 #define uart_oc2 #define timeout_timera #define timeout_timerb #define timeout_oc1 #define timeout_oc2 #define uart_ic1, uart_ic2 description needs to be defined only if uart_timera or uart_timerb is defined. define only one of these options. define uart_ic1 if the lin rx pin is connected to the input capture 1 pin. define uart_ic2 if the lin rx pin is con- nected to the input capture 2 pin. #define uart_oc1, uart_oc2 description needs to be defined only if uart_timera or uart_timerb is defined. define only one of these options. define uart_oc1 if the lin rx pin is connected to the output compare 1 pin. define uart_oc2 if the lin rx pin is connected to the output compare 2 pin. #define timeout_timera, timeout_timerb description define only one of these options. define which tim- er is used for the timeout handling. if you already defined a timer for the sci emulation set the same timer for the timeout handling. this will optimize the use of resources: a timer is fully used for the lin software and the second is free for the application. #define timeout_oc1, timeout_oc2 description define only one of these options. define which out- put compare of the previously defined timer is used for the timeout handling. warning : if the same timer is used for both the sci emulation and the timeouts handling, do not define the same output compare for both features.
19/44 lin (local interconnect network) solutions #define baudrate #define brr #define expr note: here is a list of baudrates and corresponding settings of (brr,expr) depending on the cpu frequency. note that there are some small differences in the sci prescaler between for example the st72324/321/521 and st72314/334 derivatives. as a result the value of brr and expr may also depend on the mcu derivative. table 8. example of (brr,expr) values versus baudrate and f cpu (*): f cpu =f osc /2 if pll is not used #define id_table_size #define baudrate description lin communication speed in bit/s #define brr, expr description needs to be defined only if sci is defined. set both registers to obtain the baudrate previously defined. brr is the baudrate register and expr will set the same value for both the extended re- ceive prescaler division register and the extended transmit prescaler division register. refer to the datasheet of the mcu you are using (serial com- munication interface chapter). st72x314/334/124 st72x324/321/521 f cpu (*)8mhz4mhz2mhz8mhz4mhz2mhz bit rate(bit/s) (0xd2,0x00) (0xc9,0x00) (0xc0,0x00) (0xdb,0x00) (0xd2,0x00) (0xc9,0x00) 4,8k 9,6k (0xc9,0x00) (0xc0,0x00) (0x00,0x0d) (0xd2,0x00) (0xc9,0x00) (0xc0,0x00) 19,2k (0xc0,0x00) (0x00,0x0d) high quantifi- cation error (0xc9,0x00) (0xc0,0x00) high quantifi- cation error 20k (0x00,0x19) high quantifi- cation error high quantifi- cation error (0x00,0x19) high quantifi- cation error high quantifi- cation error #define id_table_size description number of lin frames to be handled by the applica- tion. see section 3.4
20/44 lin (local interconnect network) solutions #define resynch 3.4 application interface: lin_ai.c this file is the application interface and should be filled by the user. in this way the user can define the lin communication of his application. the lin_ai.c file consists of: the id_table variable you fill this variable to define the identifiers of the lin frames that the application has to handle. each member of this list corresponds to a lin frame and its corresponding identifier. each member is of type t_id_list (see 3.2.1 type definition ) and has to be defined in the following way: { identifier, direction, data length } identifier represents the whole identifier byte including the parity bits. direction represents the data flow direction, is of type t_message_direction and should there- fore be set to id_datarequest for data being requested by the master and to be sent by the application/slave or to id_datasent for data being sent by the master to the application/ slave. data length represents the number of data bytes of the corresponding frame. it can be set be- tween 0 to 8. note : the lin protocol specification gives some advice concerning the coding of the data length through the id5 and id4 bits in the identifier byte. but this coding is no longer manda- tory since revision 1.2 of the specification. the number of members has to be entered in the lin_config.h file (see 3.3 lin configuration file: lin_config.h ). 3 notification functions the lin software is interrupt driven which means you do not have to poll any variables to handle lin communication. when activity appears on the lin bus, the lin interrupt service routine is entered and starts decoding the lin frame. once the lin software is able to notify an #define resynch description can only be defined if uart_timera or uart_timerb has been defined. if the application is working with an inaccurate clock the lin software is able to resynchronize to the master clock (refer to the lin protocol). define this symbol to activate this feature.
21/44 lin (local interconnect network) solutions event to the application, one of the 3 notification functions is called. these functions are deliv- ered empty and by expanding them the user is able to fully define his application lin commu- nication. the 3 functions correspond to the 3 kinds of events: function ubyte * datarequest_notification(@tiny t_header *header) parameters pointer to a variable of type t_header return value pointer to an array description this function is called on reception of a lin header which requests data i.e. which is defined in the id_table with the qualifier id_datarequest. the function passes the received header as a pointer. the user has to complete this function and return a pointer to the array containing the data to be sent. note: the data bytes are buffered by the lin software just after this func- tion call so that the user does not have to handle data sharing between the application and the lin software. function void datareceived_notification(@tiny t_header *header, @tiny t_response *response) parameters pointer to a variable of type t_header, pointer to a variable of type t_response return value none description this function is called upon the reception of a lin header and response which was sent by the master to the application i.e. which is defined in the id_table with the qualifierid_datasent. the function passes the re- ceived header and response as a pointer. the user has to complete this function to handle the received data. function void error_notification(t_error error_code) parameters variable of type t_error return value none description this function is called upon the detection of an error. the function passes the type of error (see t_error type definition in 3.2.1 type definition ). the user has to complete this function if special action has to be taken in case of errors.
22/44 lin (local interconnect network) solutions 4 examples the purpose of this chapter is to give you an example, describing step by step how to use the lin software. this example was defined to demonstrate the lin software and not to show a typical lin application. the network consists of the master node and 2 slave nodes. figure 9. lin network example the application example is slave1. the lin communication consists of 4 lin frames. (*): the example is given for the lin specification package 1.1 as many tools still dont support the 1.2 package. frame name identifier id[7..0] message length data direction datatoslave1 0x03 2 master to slave1 requesttoslave1 0x20 4 slave1 to master requesttoslave2 0x76 2 slave2 to master masterreq (sleep mode command) 0x80(*) 2 master to all slaves master slave 1 lin bus slave 2
23/44 lin (local interconnect network) solutions figure 10. lin communication example the figure above represents the lin communication in running mode. the sleepmo- decommand frame is sent by the master to set the lin network in sleep mode and is there- fore not part of the normal communication. the baud rate is 9600 baud. this communication corresponds to the following lin description file: master slave 1 slave 2 bus 0x76 0x03 0x20 0x03 0x20 0x76 0x03 0x20 0x03 0x20 master slave1 data tx tx tx line datatoslave1 requesttoslave1 requesttoslave2 data to slave 1 slave2 data
24/44 lin (local interconnect network) solutions figure 11. lin description file of the example the rest of the example is divided into 2 main parts. the described example is first imple- mented on the st72254g2 mcu which has no sci peripheral. this part demonstrates the ca- pability of the lin software to emulate the whole lin protocol using the embedded 16-bit timer. the second part describes the implementation on the st72334n4 which has an sci pe- ripheral. lin_description_file ; lin_protocol_version = 1.1; lin_language_version = 1.1; lin_speed = 9.6 kbps; nodes { master: master, 1 ms, 0.1 ms; slaves: slave1, slave2; } signals { masterdatatoslave1:16,5,master; slave1dataa:16,0,slave1; slave1datab:8,0,slave1; slave1datac:8,0,slave1; slave2dataa:8,0,slave2; slave2datab:8,0,slave2; } frames { datatoslave1:03,master { masterdatatoslave1,0; } requesttoslave1:32,slave1 { slave1dataa,0; slave1datab,16; slave1datac,24; } requesttoslave2:54,slave2 { slave2dataa,0; slave2datab,8; } } schedule_tables { test_schedule { datatoslave1 delay 10 ms; requesttoslave1 delay 15 ms; requesttoslave2 delay 15 ms; } }
25/44 lin (local interconnect network) solutions 4.1 implementation on the st72254g2 - software emulated sci 4.1.1 step by step configuration lin_config.h setting group comments text line in lin_config.h cpu operating frequency an external resonator of 16 mhz is used. as a result the internal cpu frequency is 8mhz. so fcpu is set to 8000000. #define fcpu 8000000 communication peripheral the st72254 has no sci periph- eral on chip. as a result the uart communication has to be emulated by one of the 16bit tim- er timera or timerb. timera is chosen in this example. as a re- sult uart_timera is defined and uart_timerb and sci are commented out. #define uart_timera //#define uart_timerb //#define sci lin rx and lin tx pin definition depending on the constraints of the board layout and according to the st72254 pinout we select the input capture 1 pin and the out- put compare 1 pin for respective- ly the lin rx and lin tx signals. the input capture 1 pin of time- ra is linked to the port b pin 0 (see pin description in the mcu datasheet). as a result lin_rx_pinnb is set to 0. port b data register has the address 0x04. as a result lin_port_add is defined to 0x04 #define uart_ic1 //#define uart_ic2 #define uart_oc1 //#define uart_oc2 #define lin_port_add 0x04 #define lin_rx_pinnb 0 timeouts the uart communication is al- ready using one input capture and one output compare of time- ra. setting timera for the timeout handling will complement the use of the timer. so we define timeout_timera. output compare 1 is already used by the uart communication (see uart_oc1) so we define the output compare 2 for the time- outs handling. #define timeout_timera //#define timeout_timerb //#define timeout_oc1 #define timeout_oc2 lin baudrate the example lin baudrate is 9600 baud. #define baudrate 9600
26/44 lin (local interconnect network) solutions lin_ai.c the first part of the lin_ai.c code is the definition of the lin frames the application has to handle. out of the 4 defined for the whole network the application handles the 3 following frames: the corresponding setting of id_table is: const t_id_list id_table[]= { {0x03, id_datasent, 2}, {0x20, id_datarequest, 4}, {0x80, id_datasent, 8} }; the second part of the lin_ai.c code consists of 3 notification functions and is the kernel of the lin communication. filling the notification functions enables you to define the behaviour of the application upon a master data request ( datarequest_notification function) on the reception of data from the master ( datareceived_notification function) and when errors occur ( error_notification function). master data request ( datarequest_notification ) the application handles one data request from the master corresponding to the identifier 0x20 ( id_table [1]). the application has to return a pointer to an array containing the data to be sent. in this example we declare an array slave_data[] . this array will be shared between the sci peripheral registers an sci peripheral is not used. as a result brr and expr are commented out. //#define brr 0xc9 //#define expr 0x00 number of lin frames to be han- dled the network communication con- sists of 4 lin frames. the appli- cation example handles 3 of them: datatoslave1, requesttoslave1 and sleepmo- decommand. #define id_table_size 3 resynchronization the application is working with a accurate clock (<2%). the resyn- chronisation feature is not need- ed. resynch is commented out. //#define resynch frame name identifier id[7..0] message length data direction datatoslave1 0x03 2 master to slave1 requesttoslave1 0x20 4 slave1 to master sleepmodecommand 0x80 2 master to all slaves setting group comments text line in lin_config.h
27/44 lin (local interconnect network) solutions application updating it with the latest data and the lin communication sending its content on request of the master. the corresponding code for the datarequest_notification function is: data reception ( datareceived_notification ) the application handles 2 data frames from the master corresponding to the identifier 0x03 and 0x80. the first frame is part of the normal communication. the second frame is a sleep command frame that can be sent by the master at any time to interrupt normal communication and set all nodes into low power mode. on reception of the first frame the application saves the received data into the variable master_data[] . on reception of the sleep command frame the application sets the st7 in halt mode. before setting the st7 in halt mode the wake-up sources should be acitivated. an application func- tion, ports_wakeup_on(), is called. two pins are configured as interrupt and will wake the st7 up on a corresponding interrupt request. the first pin is the laniards pin. as a result any bus activity will wake the application up. the second is an application pin that should be also able to wake up the application. the corresponding code for the datareceived_notification function is: any activity on the bus will wake up the st7 out of halt mode. as soon as the st7 is ready to execute the next instruction any incoming frame can be received. extern ubyte slave_data[]; ubyte * datarequest_notification(@tiny t_header *header) { if(header->identifier == id_table[1].id){ return(slave_data); } } extern ubyte master_data[]; void datareceived_notification(@tiny t_header *header, @tiny t_response *re- sponse) { if(header->identifier == id_table[0].id){ master_data[0]=response->data[0]; master_data[1]=response->data[1]; } else if(header->identifier == id_table[2].id){ ports_wakeup_on(); _asm("halt\n"); } }
28/44 lin (local interconnect network) solutions the application can also be woken up by a sensor connected to one pin of the st7 and then should also wake up the whole lin network. for this a wake-up frame has to be sent, which is done by the lin_sendwakeupsignal() function. this function is therefore inserted in the ap- plication wake-up interrupt: the software is ready! 4.2 implementation on the st72334n4 - hardware sci 4.2.1 step by step configuration 4.2.1.1 lin_config.h @interrupt void ports_0_interrupt(void) { unsigned char i; i=250; while(i--); if(!(padr&0xfe)) { paor&=0xfe; lin_sendwakeupsignal(); } } setting group comments text line in lin_config.h cpu operating frequency an external 16 mhz resonator is used. as a result the internal cpu frequency is 8 mhz. so fcpu is set to 8000000. #define fcpu 8000000 communication peripheral the st72334n4 has an on chip sci peripheral. as a result sci is defined, uart_timera and uart_timerb are comment- ed out. //#define uart_timera //#define uart_timerb #define sci lin rx and lin tx pin definitions these are not needed when us- ing an on-chip sci peripheral. all symbols are commented out. //#define uart_ic1 //#define uart_ic2 //#define uart_oc1 //#define uart_oc2 //#define lin_port_add 0x04 //#define lin_rx_pinnb 0
29/44 lin (local interconnect network) solutions 4.2.1.2 lin_ai.c the first part of the lin_ai.c code is the definition of the lin frames the application has to handle. out of the 4 defined for the whole network the application handles the 3 following frames: the corresponding setting of id_table is: const t_id_list id_table[]= { {0x03, id_datasent, 2}, {0x20, id_datarequest, 4}, {0x80, id_datasent, 8} }; the second part of the lin_ai.c code consists of 3 notification functions and is the kernel of the lin communication. filling the notification functions enables you to define the behaviour of the application upon a master data request ( datarequest_notification function) upon the recep- tion of data from the master ( datareceived_notification function) and upon errors ( error_notification function). timeouts one output compare of one timer is needed for the timeouts han- dling. we choose the output com- pare 1 of timer a. so timeout_timera and timeout_oc1 are defined. #define timeout_timera //#define timeout_timerb #define timeout_oc1 //#define timeout_oc2 lin baudrate the example lin baudrate is 9600 baud. #define baudrate 9600 sci peripheral registers see table 8. example of (brr,expr) values versus baudrate and fcpu . //#define brr 0xc9 //#define expr 0x00 number of lin frames to be han- dled the network communication con- sists of 4 lin frames. the appli- cation example handles 3 of them: datatoslave1, requesttoslave1 and sleepmo- decommand. #define id_table_size 3 resynchronization not supported using the on-chip sci peripheral. resynch is commented out. //#define resynch frame name identifier id[7..0] message length data direction datatoslave1 0x03 2 master to slave1 requesttoslave1 0x20 4 slave1 to master sleepmodecommand 0x80 2 master to all slaves
30/44 lin (local interconnect network) solutions 4.2.1.3 master data request ( datarequest_notification ) the application handles one data request from the master corresponding to the identifier 0x20 ( id_table [1]). the application has to return a pointer to an array containing the data to be sent. in this example we declare an array slave_data[] . this array will be shared between the application updating it with the last data and the lin communication sending its contents on request of the master. the corresponding code for the datarequest_notification function is: 4.2.1.4 data reception ( datareceived_notification ) the application handles 2 data frames from the master corresponding to the identifier 0x03 and 0x80. the first frame is part of the normal communication. the second frame is a sleep command frame that can be sent by the master at any time to interrupt the normal communi- cation and set all nodes into low power mode. on reception of the first frame the application saves the received data into the variable master_data[] . on reception of the sleep command frame the application sets the st7 in halt mode. before setting the st7 in halt mode the wake-up sources should be acitivated. an application func- tion, ports_wakeup_on(), is called. two pins are configured as interrupt and will wake the st7 up upon a corresponding interrupt request. the first pin is connected to the lin_rx pin (the sci rx pin has no interrupt capability). as a result any bus activity will wake the ap- plication up. the second is an application pin that should be also able to wake up the applica- tion. the corresponding code for the datareceived_notification function is: any activity on the bus will wake up the st7 out of halt mode. as soon as the st7 is ready to execute the next instruction any incoming frame can be received. the application can also be woken up by a sensor connected to one pin of the st7 and then should also wake up the whole lin network. to do this, a wake-up frame has to be sent, which is done by the lin_sendwakeupsignal() function. this function is therefore inserted in the application wake-up interrupt routine: the last point to be configured is the timeout handling and the setting of the corresponding timer, which is timer a. the application software is not using timer a for other purposes. as de- extern ubyte slave_data[]; ubyte * datarequest_notification(@tiny t_header *header) { if(header->identifier == id_table[1].id){ return(slave_data); } }
31/44 lin (local interconnect network) solutions scribed in 3.2.2 user interface functions the application is responsible for the initialization and the interrupt routine. initialization: firstly, the output compare must be configured: the ocie flag of the tacr1 register must be set and the defined oc disabled by writing the high byte of the oc1 register. as the applica- tion is not using oc2 it is disabled also in the same way. secondly, the timer prescaler must be calculated using the equations given in table 7 : 1st test: prescaler=2 (fcpu/ prescaler /baudrate)*165= 8000000/2/9600*165=68750 > 65536 doesnt match 1st test: prescaler=4 (fcpu/ prescaler /baudrate)*165= 8000000/4/9600*165=34375 < 65536 match! the prescaler has to be set to 4 which corresponds to writing the value (0,0) in the (cc0,cc1) bits in timer a control register 2. extern ubyte master_data[]; void datareceived_notification(@tiny t_header *header, @tiny t_response *re- sponse) { if(header->identifier == id_table[0].id){ master_data[0]=response->data[0]; master_data[1]=response->data[1]; } else if(header->identifier == id_table[2].id){ ports_wakeup_on(); _asm("halt\n"); } } @interrupt void ports_0_interrupt(void) { unsigned char i; i=250; while(i--); if(!(padr&0xfe)) { paor&=0xfe; lin_sendwakeupsignal(); } } on-chip sci used (fcpu/ prescaler /baudrate)*165 < 65536
32/44 lin (local interconnect network) solutions the corresponding initialization code is: interrupt: the timer is only used for the timeout handling so the lintimeout_interrupt function just needs to be called in the timer a interrupt service routine defined by the application which cor- responds to the following code: tacr1=0x40; tacr2=0x00; tasr; taoc2_l; taoc2_h=0x55; tasr; taoc1_l; taoc1_h=0x55; /* -output compare interrupt enabled */ /* prescaler = 4 */ /* erase oc2f flag and */ /* and disable it */ /* erase oc1f flag and */ /* and disable it */ /*------------------------------------------------------------------------------ routine name : tima_init input/output : none description : configure the timer a comments : ------------------------------------------------------------------------------*/ void tima_init(void) { } void lintimeout_interrupt(void); /*------------------------------------------------------------------------------ routine name : tima_interrupt input/output : none description : timer interrupt service routine comments : ------------------------------------------------------------------------------*/ @interrupt void tima_interrupt(void) { lintimeout_interrupt(); }
33/44 lin (local interconnect network) solutions the software is ready! 4.3 stmicroelectronics lin package - example installation 4.3.1 lin package the lin software is delivered in a package including the software itself, this application note and the above examples for the st72254 and the st72334 mcus. figure 12. stmicroelectronics lin package you will receive a zip file called st_lin.zip that will generate the above directory tree. create a new folder we will call the working directory and extract the files into it. the directory tree and architecture are the same for both example. figure 13. example directory tree 4.3.2 quick start with stvd7 and cosmic c compiler in order to make the examples run you need the following software to be installed: -stvd7: stmicroelectronics visual debugger for the st7 microcontroller family with inte- grated editing and environment features. this software is free of charge. you can download it by accessing the stmicroelectronics mcu homepage: mcu.st.com st_lin an examples 254 334 lin_v2.0 application note st72254 mcu example st72334 mcu example lin software revision 2.0 config sources 254 (resp.334) st7 configuration files files generated by compiler st7 hardware register lin software object lin (makefile, linker file, lin description file) main file declaration
34/44 lin (local interconnect network) solutions C cosmic c compiler: cosmic c compiler for the st7 target. for further information or con- tacts go to: http://www.cosmic-software.com/ in order to be able to compile and start a debug session and even flash an st7 mcu with the example code you need to create a new stvd7 workspace and configure your cosmic tools installation directory. C create a new stvd7 project: start the stvd7 software. first check that the cosmic compiler installation directory is configured: project>toolchains path... under cosmic builder path enter (if not already configured) the compiler path (where cxst7.exe is located). we are ready to create a new project. select file>new workspace. under workspace filename enter 334env (or 254env). under workspace location enter the examples direc- tories: \st_lin\examples\334 (or \st_lin\ex- amples\254). click on next. fill in the next dialog box as follows: figure 14. project configuration click ok. to have easy access to your source files, configure the source file directories in the work- space window. the example has 3 folders containing the source files: or object\254env.elf
35/44 lin (local interconnect network) solutions \st_lin\examples\334\sources\ (or -\254\sources) main file location (application code location) \st_lin\examples\334\sources\lin (or -\254\sources\lin) lin software location \st_lin\examples\334\sources\st7 (or -\254\sources\st7) hardware register declaration the workspace window should look like this: figure 15. workspace window configuration the workspace is ready. save it in the working directory: file>save workspace - cosmic installation path the examples are delivered with all necessary configuration files like makefiles and linker files. as far as possible paths are given that are relative to the working directory so you dont
36/44 lin (local interconnect network) solutions need to update them when you move the example to another directory/pc. one file contains absolute paths: the linker file located in \st_lin\examples\334\config (or -\254\config) and named 334env.lkf (resp. 254env.lkf). you need to enter 3 paths. edit the file. see figure 16 : figure 16. cosmic linker file configuration in place of (3 times) enter your cosmic compiler instal- lation path (path of cxst7.exe). for example replace \lib\crtsx.st7 by c:\cosmic\\lib\crtsx.st7. save the file. the example is ready. you can build the example (f7). build will generate a 334env.elf (or 254env.elf) for debugging and a 334env.s19 (254env.s19) for flashing an mcu. refer to the stvd7 documentation for details using of the stvd7 editor and debugger. 4.4 performance the above examples correspond to the 2 main kinds of software configuration, the sci com- munication emulated by software or supported by the hardware sci peripheral. the corre- ... +seg .share -a uzpage -is -sram \lib\crtsx.st7 # startup routine ..\object\main.o # application program ..\object\adc.o ..\object\crs.o ..\object\eep.o ..\object\mcc.o ..\object\misc.o ..\object\ports.o ..\object\sci.o ..\object\spi.o ..\object\tima.o ..\object\timb.o ..\object\trap.o ..\object\lin.o ..\object\lin_ai.o \lib\libm.st7 \lib\libims.st7 +seg .const -b 0xffe0 -k # vectors start address ..\object\vector.o # interrupt vectors ...
37/44 lin (local interconnect network) solutions sponding software performance is different. table 9 and table 10 give performance summa- ries for both examples. table 9. st72254 example performance summary table 10. st72334 example performance summary 4.4.1 timing considerations the runtime performance of the software depends on many parameters like the memory model, the compiler options and the compiler version and also on the application (lin_ai.c is part of the lin interrupt). as a result it is impossible to give generally applicable software runtime performance data. a first timing consideration is the maximum reachable speed running the software without any application software. in this case only the software emulating the sci communication (st72254 example) has speed limitations. in the above st72254 example the maximum speed reachable was 16kbaud. the software using the on-chip sci peripheral has no lin speed limitation. then if you add some application code in the lin_ai.c file, you make the lin interrupt service routine longer and therefore decrease the software performance. thats why in order to achieve better performance you should keep actions done in the lin_ai.c file as short as pos- sible. nevertheless the software that uses the on-chip sci peripheral should not be speed lim- ited under 20kbaud. the final timing consideration is when the application software needs to interrupt the lin com- munication. the lin software is interrupt-driven and between two interrupts the application software can run some other code. as long as the application software is interruptable, the lin software will interrupt it when needed. problems can occur if the application software is not in- compiler version v4.3a memory model +modm - memory short compiler options +debug code size whole project 2.1 kbyte lin.o 1.8 kbyte lin_ai.o 44 byte lin interrupt - cpu load 17% max lin baudrate @16mhz 16kbaud compiler version v4.3a memory model +modms - memory small compiler options +debug code size whole project 1.4 kbyte lin.o 1.0 kbyte lin_ai.o 44 byte lin interrupt - cpu load 2% max lin baudrate @16mhz no limit-20kbaud
38/44 lin (local interconnect network) solutions terruptable for a long time so that the lin interrupt is called too late and an event is lost (bit/ byte). as too many parameters are involved its impossible to give generally-applicable per- formance data. therefore we implemented a timing analysis feature (debug_mode) you can activate when debugging your software. this feature can be activated in the lib.h file using 5 symbols: the final piece of information you need to do the timing analysis is how much can the applica- tion delay the occurrence of the lin interrupt? for this we need to go into more detail to ana- lyze the way the software is handling each bit/byte. once again, depending on whether the sci communication is emulated or not the software is works in very different ways: 4.4.2 using the emulated sci figure 17. sci emulation: lin reception #define debug_mode description when defined, this activates the timing debug fea- ture. this feature configure an pin as output and uses it to indicate when the lin interrupt is entered (set) and when it is left (reset). #define debug_pxdradd debug_pxddradd debug_pxoradd description to configure the used i/o pin, first define these symbols to the address of the corresponding data register, data direction register and option register. #define debug_lin_it_pin description set this symbol to the pin number used (ex: 5 when using pc5) ic oc oc oc oc oc oc oc oc oc oc cpu not used for lin lin interrupt running lin bus
39/44 lin (local interconnect network) solutions 4.4.2.1 reception the sci is emulated by software using the input capture and output compare of the on-chip 16-bit timer. when the bus is idle, the software waits for a negative edge: the input capture in- terrupt is activated and calls the lin interrupt when a negative edge occurs. the input capture time is used to generate an output compare in the middle of this first bit. the lin interrupt rou- tine returns to the calling program. when the output compare event occurs the lin interrupt is called again . the bus level is checked and a new output compare is set to occur in the middle of the next bit. this last process is repeated until the stop bit. as a result the application software should not: C delay the occurrence of the ic interrupt too much. specifically: a problem occurs if the first output compare is set after the expected occurrence of the output compare event, which is the middle of the bit. so as long as the ic interrupt ends before the middle of the bit, the delay is acceptable. see figure 18 . figure 18. ic interrupt handing in reception mode C delay the occurrence of each oc interrupt too much. specifically: a problem occurs if the sample time defined at the beginning of the interrupt is delayed so that it occurs after the end of the bit. see figure 19 . start bit application task ic request ic interrupt served deadline for end of ic interrupt 1/2 1/2
40/44 lin (local interconnect network) solutions figure 19. oc interrupt handling in reception mode 4.4.2.2 transmission for transmission the software only uses the output compare feature of the 16-bit timer. for each bit, two oc interrupts are generated. the first one is generated to output the value of the new bit. the second is used to read back the bus and check whether the output value is actu- ally being sent, in other words to check for a bit error. see figure 20 . figure 20. sci emulation: lin transmission the bit transition time is precise because the timer output compare itself outputs the new level when an output compare event occurs. software delays do not influence the bit transitions. the first oc sets a new oc for the middle of the bit. the second reads the lin bus level and prepares the next oc to output the next bit. as a result the application software should not: 1 bit application task deadline for start of oc interrupt oc request oc interrupt served 1 bit 1st oc: 2nd oc: output new bit read back
41/44 lin (local interconnect network) solutions C delay the occurrence of the first oc interrupt too much. specifically: a problem occurs if the second output compare is set after the expected time, which is the middle of the bit. so as long as the first oc interrupt ends before the middle of the bit, the delay is acceptable. see figure 21 . figure 21. handling the first oc interrupt in transmission mode C delay the occurrence of the second oc interrupt too much. specifically: a problem occurs if the sample time defined at the beginning of the interrupt is delayed outside the bit. see fig- ure 22 figure 22. handling the second oc interrupt in transmission mode 1 bit application task deadline for end of 1st 1rst oc request 1rst oc serviced oc interrupt 1 bit application task deadline for start of 2nd 2nd oc request 2nd oc serviced oc interrupt
42/44 lin (local interconnect network) solutions 4.4.3 using the on-chip sci using the on-chip sci the flexibility is considerably increased. the cpu load is very low and the capability of the application software to run at the same time as the lin software is high. firstly a lin interrupt occurs every byte instead of every bit (even every half bit in transmis- sion) in the timer solution. and secondly the received byte is buffered in hardware which al- lows a lot of flexibility. figure 23. cpu load with on-chip sci peripheral 4.4.3.1 reception the on-chip peripheral is handling the sci communication and notifies a reception at the end of each byte. a lin interrupt is then generated and handles the received data according to the lin protocol. figure 24. reception notification interrupt when the sci notifies the reception it copies at the same time the received value into a buffer. as a result the peripheral is ready for the next reception and the software can still hold the re- ceived data until the end of the new reception. afterwards an overrun condition occurs. cpu not used for lin lin interrupt running lin bus lin frame stop bit 1 byte sci reception notification lin interrupt
43/44 lin (local interconnect network) solutions as a result the application software should not delay the occurrence of the sci reception no- tification interrupt so much that an overrun condition occurs. specifically: the end the lin in- terrupt should end before the stop bit of the next byte. figure 25. reception interrupt handling 4.4.3.2 transmission in transmission delays coming from the application cannot disturb the proper working of the software. this will delay the transmission and the issue is more a timeout issue on the current transmitted frame: if the interrupt time is very long the transmitted frame may exceed the max- imum allowed frame time. the sci interrupt in transmission occurs also at the stop bit. if the occurrence of the interrupt is delayed by the application the interbyte time will increase. 5 summary of changes revision main changes date 1.0 first version august 2001 1.1 remove section how to get the lin software? april 2002 1 byte sci reception interrupt request application task interrupt served
44/44 lin (local interconnect network) solutions the present note which is for guidance only aims at providing customers with information regarding their products in order for them to save time. as a result, stmicroelectronics shall not be held liable for any direct, indirect or consequential damages with respect to any claims arising from the content of such a note and/or the use made by customers of the information contained herein in connection with their products. information furnished is believed to be accurate and reliable. however, stmicroelectronics assumes no responsibility for the co nsequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of stmicroelectronics. specifications mentioned in this publicati on are subject to change without notice. this publication supersedes and replaces all information previously supplied. stmicroelectronics prod ucts are not authorized for use as critical components in life support devices or systems without the express written approval of stmicroele ctronics. the st logo is a registered trademark of stmicroelectronics ? 2002 stmicroelectronics - all rights reserved. purchase of i 2 c components by stmicroelectronics conveys a license under the philips i 2 c patent. rights to use these components in an i 2 c system is granted provided that the system conforms to the i 2 c standard specification as defined by philips. stmicroelectronics group of companies australia - brazil - canada - china - finland - france - germany - hong kong - india - israel - italy - japan malaysia - malta - morocco - singapore - spain - sweden - switzerland - united kingdom - u.s.a. http://www.st.com


▲Up To Search▲   

 
Price & Availability of AN1278

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X